// buffer
const buffer = new ArrayBuffer(10);
console.log(buffer.byteLength);
const part = buffer.slice(1, 3);
console.log(part.byteLength);

// view
const view = new DataView(buffer, 1, 3);
view.setInt8(0, 1);
console.log(view.getInt8(0));

// array with specified type
const arr1 = new Int32Array(10);
console.log(arr1.byteLength);
console.log(arr1.length);
const arr2 = new Int16Array(buffer);
console.log(arr2.byteLength);
console.log(arr2.length);

// build from iterable objects
const arr3 = new Int8Array([1, 2]);
console.log(arr3.byteLength, arr3.length);
const arr4 = new Int16Array(new Set([1, 2, 3]));
console.log(arr4.byteLength, arr4.length);
const arr5 = new Int32Array(Array.from({
    0: '1',
    1: '2',
    '2': 3,
    length: 3
}));
console.log(Int16Array.of(1, 2, 3));
console.log(Int8Array.from('123'));

// iteration
for (let [key, value] of arr5.entries()) {
    console.log(key, value);
}
for (let key of arr5.keys()) {
    console.log(key);
}
for (let value of arr5.values()) {
    console.log(value);
}

// operation
console.log(arr5.find(x => x > 2));
const arr6 = new Int16Array(3);
arr6.set(arr5, 1);
console.log(arr6);
console.log(arr5.subarray(1, 2));
